<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="CommandStack.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>CommandStack.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'CommandStack.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="draw2d/CommandStack.html">draw2d.CommandStack</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/* This notice must be untouched at all times.

FreeGroup Draw2D 0.9.26
The latest version is available at
http://www.freegroup.de

Copyright (c) 2006 Andreas Herz. All rights reserved.
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
or see http://www.gnu.org/copyleft/lesser.html
*/</span>

<span class="comment">/**
 * 
 * <span class="attrib">@version</span> 0.9.26
 * <span class="attrib">@author</span> Andreas Herz
 * <span class="attrib">@constructor</span>
 */</span>
draw2d.CommandStack=<span class="reserved">function</span>()
{
   <span class="comment">/** <span class="attrib">@private</span> **/</span>
   <span class="reserved">this</span>.undostack = [];
   <span class="comment">/** <span class="attrib">@private</span> **/</span>
   <span class="reserved">this</span>.redostack = [];
   <span class="comment">/** <span class="attrib">@private</span> **/</span>
   <span class="reserved">this</span>.maxundo = 50;
   <span class="comment">/** <span class="attrib">@private</span> **/</span>
   <span class="reserved">this</span>.eventListeners = new draw2d.ArrayList();
};

<span class="comment">/** Constant indicating notification prior to executing a command (value is 1).*/</span>
draw2d.CommandStack.PRE_EXECUTE=1;
<span class="comment">/** Constant indicating notification prior to redoing a command (value is 2).*/</span>
draw2d.CommandStack.PRE_REDO=2;
<span class="comment">/** Constant indicating notification prior to undoing a command (value is 4).*/</span>
draw2d.CommandStack.PRE_UNDO=4;
<span class="comment">/**  Constant indicating notification after a command has been executed (value is 8).*/</span>
draw2d.CommandStack.POST_EXECUTE=8;
<span class="comment">/** Constant indicating notification after a command has been redone (value is 16).*/</span>
draw2d.CommandStack.POST_REDO=16;
<span class="comment">/** Constant indicating notification after a command has been undone (value is 32).*/</span>
draw2d.CommandStack.POST_UNDO=32;

draw2d.CommandStack.POST_MASK = draw2d.CommandStack.POST_EXECUTE | draw2d.CommandStack.POST_UNDO | draw2d.CommandStack.POST_REDO;
draw2d.CommandStack.PRE_MASK = draw2d.CommandStack.PRE_EXECUTE | draw2d.CommandStack.PRE_UNDO | draw2d.CommandStack.PRE_REDO;


<span class="comment">/** <span class="attrib">@private</span> **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.type=<span class="literal">"draw2d.CommandStack"</span>;

<span class="comment">/**
 * Set the maximal undo stack size. Entries will be remove if the max. stack 
 * size has been reached.
 *
 * <span class="attrib">@param</span> {int} count The maximal undo stack size.
 * 
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.setUndoLimit=<span class="reserved">function</span>(<span class="comment">/*:int*/</span> count)
{
  <span class="reserved">this</span>.maxundo = count;
};

<span class="comment">/**
 * Remove the undo / redo history. This is usefull if the user has been save the 
 * document.
 *
 * 
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.markSaveLocation=<span class="reserved">function</span>()
{
   <span class="reserved">this</span>.undostack = [];
   <span class="reserved">this</span>.redostack = [];
};

<span class="comment">/**
 * Executes the specified Command if possible. Prior to executing the command, a
 * draw2d.CommandStackEvent for {<span class="attrib">@link</span> #PRE_EXECUTE} will be fired to event listeners. 
 * Similarly, after attempting to execute the command, an event for {<span class="attrib">@link</span> #POST_EXECUTE}
 * will be fired.
 *
 * <span class="attrib">@param</span> {draw2d.Command} command The command to execute.
 * 
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.execute=<span class="reserved">function</span>(<span class="comment">/*:draw2d.Command*/</span> command)
{
   <span class="comment">// nothing to do</span>
   <span class="reserved">if</span>(command===null)
      <span class="reserved">return</span>; <span class="comment">//silently</span>

   <span class="comment">// return if the command can't execute or it doesn't change the model</span>
   <span class="comment">// =&gt; Empty command</span>
   <span class="reserved">if</span>(command.canExecute()==false)
      <span class="reserved">return</span>;

   <span class="reserved">this</span>.notifyListeners(command, draw2d.CommandStack.PRE_EXECUTE);

   <span class="reserved">this</span>.undostack.push(command);
   command.execute();

   <span class="comment">// cleanup the redo stack if the user execute a new command.</span>
   <span class="comment">// I think this will create a "clean" behaviour of the unde/redo mechanism.</span>
   <span class="comment">//</span>
   <span class="reserved">this</span>.redostack = [];

   <span class="comment">// monitor the max. undo stack size</span>
   <span class="comment">//</span>
   <span class="reserved">if</span>(<span class="reserved">this</span>.undostack.length &gt; <span class="reserved">this</span>.maxundo)
   {
      <span class="reserved">this</span>.undostack = <span class="reserved">this</span>.undostack.slice(<span class="reserved">this</span>.undostack.length-<span class="reserved">this</span>.maxundo);
   }
   <span class="reserved">this</span>.notifyListeners(command, draw2d.CommandStack.POST_EXECUTE);
};

<span class="comment">/**
 * Undo the command
 *
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.undo=<span class="reserved">function</span>()
{
   var command = <span class="reserved">this</span>.undostack.pop();
   <span class="reserved">if</span>(command)
   {
      <span class="reserved">this</span>.notifyListeners(command, draw2d.CommandStack.PRE_UNDO);
      <span class="reserved">this</span>.redostack.push(command);
      command.undo();
      <span class="reserved">this</span>.notifyListeners(command, draw2d.CommandStack.POST_UNDO);
   }
};

<span class="comment">/** Redo the command after the user has undo this command
 *
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.redo=<span class="reserved">function</span>()
{
   var command = <span class="reserved">this</span>.redostack.pop();

   <span class="reserved">if</span>(command)
   {
      <span class="reserved">this</span>.notifyListeners(command, draw2d.CommandStack.PRE_REDO);
      <span class="reserved">this</span>.undostack.push(command);
      command.redo();
      <span class="reserved">this</span>.notifyListeners(command, draw2d.CommandStack.POST_REDO);
   }
};

<span class="comment">/**
 * Return the Redo text of the next REDO command.
 *
 * <span class="attrib">@type</span> String
 * <span class="attrib">@since</span> 0.9.24
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.getRedoLabel=<span class="reserved">function</span>()
{
   <span class="reserved">if</span>(<span class="reserved">this</span>.redostack.lenght===0)
     <span class="reserved">return</span> <span class="literal">""</span>;
     
   var command = <span class="reserved">this</span>.redostack[<span class="reserved">this</span>.redostack.length-1];

   <span class="reserved">if</span>(command)
   {
      <span class="reserved">return</span> command.getLabel();
   }
   <span class="reserved">return</span> <span class="literal">""</span>;
};


<span class="comment">/**
 * Return the Undo text of the next REDO command.
 *
 * <span class="attrib">@type</span> String
 * <span class="attrib">@since</span> 0.9.24
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.getUndoLabel=<span class="reserved">function</span>()
{
   <span class="reserved">if</span>(<span class="reserved">this</span>.undostack.lenght===0)
     <span class="reserved">return</span> <span class="literal">""</span>;
     
   var command = <span class="reserved">this</span>.undostack[<span class="reserved">this</span>.undostack.length-1];

   <span class="reserved">if</span>(command)
   {
      <span class="reserved">return</span> command.getLabel();
   }
   <span class="reserved">return</span> <span class="literal">""</span>;
};


<span class="comment">/**
 * <span class="attrib">@type</span> boolean
 * <span class="attrib">@returns</span> &lt;code&gt;true&lt;/code&gt; if it is appropriate to call {<span class="attrib">@link</span> #redo()}.
 */</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.canRedo=<span class="reserved">function</span>()
{
   <span class="reserved">return</span> <span class="reserved">this</span>.redostack.length&gt;0;
};

<span class="comment">/**
 * <span class="attrib">@type</span> boolean
 * <span class="attrib">@returns</span> &lt;code&gt;true&lt;/code&gt; if {<span class="attrib">@link</span> #undo()} can be called
 **/</span> 
draw2d.CommandStack.<span class="reserved">prototype</span>.canUndo=<span class="reserved">function</span>()
{
   <span class="reserved">return</span> <span class="reserved">this</span>.undostack.length&gt;0;
};

<span class="comment">/**
 * Adds a listener to the command stack, which will be notified whenever a command has been processed on the stack.
 * <span class="attrib">@param</span> {draw2d.CommandStackListener} listener the listener to add.
 */</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.addCommandStackEventListener=<span class="reserved">function</span>(<span class="comment">/*:draw2d.CommandStackEventListener*/</span> listener)
{
    <span class="reserved">if</span>(listener instanceof draw2d.CommandStackEventListener)
      <span class="reserved">this</span>.eventListeners.add(listener);
    <span class="reserved">else</span>
      throw <span class="literal">"Object doesn't implement required callback interface [draw2d.CommandStackListener]"</span>;
};

<span class="comment">/**
 * Removes a listener from the command stack.
 * <span class="attrib">@param</span> {draw2d.CommandStackListener} listener the listener to remove.
 */</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.removeCommandStackEventListener=<span class="reserved">function</span>(<span class="comment">/*:draw2d.CommandStackEventListener*/</span> listener)
{
   <span class="reserved">this</span>.eventListeners.remove(listener);
};

<span class="comment">/**
 * Notifies command stack event listeners that the command stack has changed to the
 * specified state.
 * 
 * <span class="attrib">@param</span> {draw2d.Command} command the command
 * <span class="attrib">@param</span> {int} state the current stack state
 *
 **/</span>
draw2d.CommandStack.<span class="reserved">prototype</span>.notifyListeners=<span class="reserved">function</span>(<span class="comment">/*:draw2d.Command*/</span> command, <span class="comment">/*:int*/</span> state)
{
  var event = new draw2d.CommandStackEvent(command, state);
  var size = <span class="reserved">this</span>.eventListeners.getSize();
  <span class="reserved">for</span> (var i = 0; i &lt; size; i++)
     <span class="reserved">this</span>.eventListeners.get(i).stackChanged(event);
};
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Mon Nov 14 13:45:39 2011</div>
</body>
</html>
